package ai.phase.cognition.development;

public class RegionDeltaSpec 
{
	private enum DESIGTYPE
	{
		INCREMENT, DECREMENT,POSITIVE, NEGATIVE,NEUTRAL,EXPLICIT
	}
	
	DESIGTYPE j_DType;
	int j_RegionId;
	int j_Utility;
	
	private static final String j_SpecSeparator="_";
	public void UpdateRegion(RegionDesignator designator)
	{
		designator.SetId(j_RegionId);
		switch (j_DType)
		{
			case INCREMENT:
				designator.IncrementUtility();
				return;
			case DECREMENT:
				designator.DecrementUtility();
				return;
			case POSITIVE:
				designator.SetPositive();
				return;
			case NEGATIVE:
				designator.SetNegative();
				return;
			case EXPLICIT:
				designator.SetValue(j_Utility);
				return;
			default:
				designator.SetNeutral();
		}
	}
	
	private RegionDeltaSpec(int id, DESIGTYPE dType)
	{
		this.j_DType=dType;
		this.j_RegionId=id;
	}
	
	private RegionDeltaSpec(int id, DESIGTYPE dType, int utility)
	{
		this.j_DType=dType;
		this.j_RegionId=id;
		j_Utility=utility;
	}
	
	
	public static RegionDeltaSpec CompileSpec(String specString)
	{
		String[] specParts = specString.split(j_SpecSeparator);
		String idPart=specParts[0].trim();
		String utilityType=specParts[1].trim();
		int rId=Integer.parseInt(idPart);
		DESIGTYPE dType;
		if (utilityType.equals("+"))
			dType=DESIGTYPE.POSITIVE;
		else if (utilityType.equals("-"))
			dType=DESIGTYPE.NEGATIVE;
		else if (utilityType.equals("++"))
			dType=DESIGTYPE.INCREMENT;
		else if (utilityType.equals("--"))
			dType=DESIGTYPE.DECREMENT;
		else
		{
			try
			{
				int u = Integer.parseInt(utilityType);
				return new RegionDeltaSpec(rId, DESIGTYPE.EXPLICIT,u);
			}
			catch (Exception e)
			{
				
			}
			dType=DESIGTYPE.NEUTRAL;
		}
		return new RegionDeltaSpec(rId,dType);
		
	}
}
